/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Hogar;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Fcalefaccion extends Canvas implements CommandListener{
private Temper temp;
private Gauge nivel;
private Ticker tick;
private Command atras, aceptar, acptemp;
private int[][] coordTemp;
private boolean estado;
private Image planta;
private int[] coordRect;
private Hogar midlet;
public Fcalefaccion(Hogar midlet){
this.midlet = midlet; //Guardo la referencia del MIDlet
temp = new Temper(midlet);
coordRect = new int[4];
planta = midlet.edificio.getPlanta();
coordTemp = new int[midlet.edificio.getNumHabitaciones()][2];
tick = new Ticker("Climatización");
atras = new Command("Atras",Command.BACK,1);
aceptar = new Command("Aceptar",Command.OK,1);
this.setTicker(tick);
this.addCommand(atras);
this.setCommandListener(this);
}
public void paint(Graphics g){
coordTemp = midlet.edificio.getCoordTemp();
g.drawImage(planta,0,0,Graphics.TOP|Graphics.LEFT);
dibujarTemperaturas(g);
g.setColor(255,0,0);
g.drawRect(coordRect[0],coordRect[1],
coordRect[2],coordRect[3]);
}
public void dibujarTemperaturas(Graphics g){
g.setColor(255,255,255);
for (int i=0;i<midlet.edificio.getNumHabitaciones();i++){
g.drawString(""+midlet.edificio.getTemperatura(i),
coordTemp[i][0],coordTemp[i][1],
Graphics.TOP|Graphics.LEFT);
}
}
public void commandAction(Command c, Displayable d){
if (c == atras){
midlet.verOpciones();
}else if (c == acptemp){
midlet.pantalla.setCurrent(this);
repaint();
}
}
public void keyPressed(int codigo){
int ncod = getGameAction(codigo);
int[] ncoord;
switch (ncod){
case Canvas.FIRE:{
midlet.pantalla.setCurrent(temp);
break;
}
case Canvas.UP:{
ncoord = midlet.edificio.mostrarPlanta(0);
for (int i=0;i<4;i++)
coordRect[i] = ncoord[i];
break;
}
case Canvas.DOWN:{
ncoord = midlet.edificio.mostrarPlanta(1);
for (int i=0;i<4;i++)
coordRect[i] = ncoord[i];
break;
}
case Canvas.RIGHT:{
ncoord = midlet.edificio.mostrarPlanta(2);
for (int i=0;i<4;i++)
coordRect[i] = ncoord[i];
break;
}
case Canvas.LEFT:{
ncoord = midlet.edificio.mostrarPlanta(3);
for (int i=0;i<4;i++)
coordRect[i] = ncoord[i];
break;
}
}
ncoord = null;
repaint();
}
public void setCoord(int[] c){
for (int i=0;i<4;i++)
coordRect[i] = c[i];
}
public void setCoordTemp(int[][] c){
coordTemp = c;
}
}
